package com.yc.resfoods.configs;

import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName CustomerExceptionHandler
 * @since: 2023/8/20 16:02
 * @auth: kirito
 * @description: springboot统一异常处理  处理的必须是controller中的异常
 **/
@ControllerAdvice
@Order(-100000)
public class CustomerExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    private Map<String, Object> handleRuntimeException(RuntimeException exception) {
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "runtimeException occured");
        return map;
    }
}
